package com.bjpowernode.springboot.web;

import com.bjpowernode.springboot.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class StudentController {

    @RequestMapping(value = "/student")
    public Object student( Integer id, String name){
        Student student = new Student();
        student.setId(id);
        student.setName(name);
        return student;
    }


    //@RequestMapping(value = "/student/detail/{id}/{age}")
    @GetMapping(value = "/student/detail/{id}/{age}")
    public Object student1(@PathVariable("id") Integer id,
                           @PathVariable("age") Integer age){

        Map<String,Object> retMap = new HashMap<>();
        retMap.put("id",id);
        retMap.put("age",age);
        return retMap;
    }

    //@RequestMapping(value = "/student/detail/{id}/{status}")
    @DeleteMapping(value = "/student/detail/{id}/{status}")
    public Object student2(@PathVariable("id") Integer id,
                           @PathVariable("status") Integer age){

        Map<String,Object> retMap = new HashMap<>();
        retMap.put("id",id);
        retMap.put("status",age);
        return retMap;
    }
    //以上代码的student1和student2会出现请求路径模糊的错误
    //通常在RESTful风格中方法的请求方式会被增删改查的请求方式区分


    //@RequestMapping(value = "/student/detail/{id}/{status}")
    @DeleteMapping(value = "/student/{id}/detail/{city}")
    public Object student3(@PathVariable("id") Integer id,
                           @PathVariable("city") Integer city){

        Map<String,Object> retMap = new HashMap<>();
        retMap.put("id",id);
        retMap.put("city",city);
        return retMap;
    }

    @PostMapping(value = "/student/{id}")
    public String addStudent(@PathVariable("id") Integer id){
        return "add student ID:" + id;
    }

    @PutMapping(value = "/student/{id}")
    public String  updateStudent(@PathVariable("id") Integer id){
        return "update Student ID:" + id;
    }

}
